package cn.edu.njust.utils;

import cn.edu.njust.alg.leetcode.ListNode;

public class ListNodeUtils {

	public static void printList(ListNode head) {
		while (head != null) {
			System.out.print(head.val);
			if (head.next != null) {
				System.out.print("->");
			}
			head = head.next;
		}
		System.out.println();
	}

	public static ListNode createList(int[] a) {
		if (a == null || a.length == 0) {
			return null;
		}
		ListNode p = null;
		ListNode q = null;
		for (int i = a.length - 1; i >= 0; i--) {
			q = p;
			p = new ListNode(a[i]);
			p.next = q;
		}
		return p;

	}

	public static void main(String[] args) {
		int[] a = { 1, 4, 3, 2, 5, 2 };
		ListNode h = ListNodeUtils.createList(a);
		ListNodeUtils.printList(h);
	}

}
